import Vue from 'vue'
import VueRouter from 'vue-router'
import myHome from '../views/myHome.vue'
import NotFound from '../views/NotFound.vue'

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)
//路由
const routes = [
  {
    path: '/',
    name: 'myHome',
    component: myHome,
    meta: {
      title: "主页",
    }
  },
  {
    path: '/mylogin',
    name: 'myLogin',
    component: () => import('../views/myLogin.vue'),
    meta: {
      title: "登录",
    }
  },
  {
    path: '/userhome',
    name: 'userHome',
    component: () => import('../views/userHome.vue'),
    meta: {
      title: "后台主页",
    }
  },
  {
    path: '/adminhome',
    name: 'adminHome',
    component: () => import('../views/adminHome.vue'),
    meta: {
      title: "管理员主页",
    }
  },

  {
    path: "/404",
    name: '404',
    component: NotFound,
    meta: {
      title: "404"
    },
  },
  {
    path: "*",
    redirect: "/404",
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
